home *** CD-ROM | disk | FTP | other *** search
- head 1.4;
- branch ;
- access ;
- symbols sprited:1.4.1;
- locks ; strict;
- comment @ * @;
-
-
- 1.4
- date 90.09.11.14.28.37; author kupfer; state Exp;
- branches 1.4.1.1;
- next 1.3;
-
- 1.3
- date 89.10.03.22.04.50; author jhh; state Exp;
- branches ;
- next 1.2;
-
- 1.2
- date 88.06.27.17.23.41; author ouster; state Exp;
- branches ;
- next 1.1;
-
- 1.1
- date 88.06.19.14.33.16; author ouster; state Exp;
- branches ;
- next ;
-
- 1.4.1.1
- date 91.10.22.14.54.18; author kupfer; state Exp;
- branches ;
- next ;
-
-
- desc
- @@
-
-
- 1.4
- log
- @Use function prototypes.
- @
- text
- @/*
- * Time_ToParts.c --
- *
- * Source code for the Time_ToParts library procedure.
- *
- * Copyright 1988 Regents of the University of California
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies. The University of California
- * makes no representations about the suitability of this
- * software for any purpose. It is provided "as is" without
- * express or implied warranty.
- */
-
- #ifndef lint
- static char rcsid[] = "$Header: /sprite/src/lib/c/time/RCS/Time_ToParts.c,v 1.3 89/10/03 22:04:50 jhh Exp Locker: kupfer $ SPRITE (Berkeley)";
- #endif not lint
-
- #include <sprite.h>
- #include <spriteTime.h>
-
- /*
- * Forward declarations:
- */
- static int YearLength _ARGS_((int year));
-
-
- /*
- *----------------------------------------------------------------------
- *
- * YearLength --
- *
- * Result:
- * The number of days in the year.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-
- static int
- YearLength(year)
- int year;
- {
- if (year%400 == 0) {
- return(366);
- }
- if (year%100 == 0) {
- return(355);
- }
- if (year%4 == 0) {
- return(366);
- }
- return(365);
- }
-
- /*
- *----------------------------------------------------------------------
- *
- * Time_ToParts --
- *
- * Converts a time value into its components.
- * If relative time is specified, the time is broken down to days,
- * hours, minutes and seconds only.
- *
- * Modified from UNIX ctime.c -- NEEDS TO BE REWRITTEN!!
- *
- * Results:
- * None.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-
- void
- Time_ToParts(time, relativeTime, partsPtr)
- int time;
- Boolean relativeTime;
- register Time_Parts *partsPtr;
- {
- int hms, day;
- int dayOfMonth, month, year;
- Boolean negative;
- static int monthLengths[] = {
- 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
- static int leapMonthLengths[] = {
- 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
- int *monthLenPtr;
-
- /*
- * break initial number into days
- */
-
- if (time < 0) {
- negative = TRUE;
- time = -time;
- } else {
- negative = FALSE;
- }
- hms = time % 86400;
- day = time / 86400;
- if (hms<0) {
- hms += 86400;
- day -= 1;
- }
-
- /*
- * generate hours:minutes:seconds
- */
- partsPtr->seconds = hms % 60;
- hms /= 60;
- partsPtr->minutes = hms % 60;
- partsPtr->hours = hms / 60;
-
- /*
- * For a relative time, determine days, hours, minutes and seconds only.
- */
-
- if (relativeTime) {
- if (negative) {
- partsPtr->dayOfYear = -day;
- } else {
- partsPtr->dayOfYear = day;
- }
- return;
- }
-
- /*
- * day is the day number.
- * generate day of the week.
- * The addend is 4 mod 7 (1/1/1970 was Thursday)
- */
-
- partsPtr->dayOfWeek = (day + 7340036) % 7;
-
- /*
- * year number
- */
- if (day >= 0) {
- for(year=70; day >= YearLength(year); year++) {
- day -= YearLength(year);
- }
- } else {
- for (year=70; day<0; year--) {
- day += YearLength(year-1);
- }
- }
- partsPtr->year = year;
- partsPtr->dayOfYear = day;
-
- /*
- * generate month
- */
-
- if (YearLength(year)==366) {
- monthLenPtr = leapMonthLengths;
- } else {
- monthLenPtr = monthLengths;
- }
-
- for (dayOfMonth = day, month=0;
- dayOfMonth >= monthLenPtr[month];
- month++) {
- dayOfMonth -= monthLenPtr[month];
- }
- dayOfMonth += 1;
- partsPtr->dayOfMonth = dayOfMonth;
- partsPtr->month = month;
- }
-
- /*
- *----------------------------------------------------------------------
- *
- * Time_FromParts --
- *
- * Converts components of a time into a time value.
- * If relative time is specified, the time comprised of days,
- * hours, minutes and seconds only.
- *
- * Modified from UNIX ctime.c -- NEEDS TO BE REWRITTEN!!
- * IMPORTANT: won't do dates before 1970!!!
- *
- * Results:
- * SUCCESS if time was converted, FAILURE otherwise.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-
- ReturnStatus
- Time_FromParts(partsPtr,relativeTime, timePtr)
- register Time_Parts *partsPtr;
- Boolean relativeTime;
- int *timePtr;
- {
-
- #define CENTURY 1900
-
- int month, year;
- static int monthLengths[] = {
- 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
- static int leapMonthLengths[] = {
- 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
- int *monthLenPtr;
- int days;
- int seconds;
- int dayOfYear = 0;
-
- if (partsPtr->year < 70) {
- return FAILURE;
- }
- if ((partsPtr->dayOfMonth == -1) && (partsPtr->dayOfYear == -1)) {
- return FAILURE;
- }
- days = 0;
- if (!relativeTime) {
- for (year = 1970; year < partsPtr->year + CENTURY; year++) {
- days += YearLength(year);
- }
- if (partsPtr->dayOfMonth != -1) {
- if (YearLength(partsPtr->year + CENTURY) == 366) {
- monthLenPtr = leapMonthLengths;
- } else {
- monthLenPtr = monthLengths;
- }
- for (month = 0; month < partsPtr->month; month++) {
- dayOfYear += monthLenPtr[month];
- }
- dayOfYear += partsPtr->dayOfMonth - 1;
- if (partsPtr->dayOfYear != -1) {
- if (dayOfYear != partsPtr->dayOfYear) {
- return FAILURE;
- }
- }
- } else {
- dayOfYear = partsPtr->dayOfYear;
- }
- }
- days += dayOfYear;
- seconds = days * (24 * 60 * 60);
- seconds += partsPtr->hours * 60 * 60;
- seconds += partsPtr->minutes * 60;
- seconds += partsPtr->seconds;
- *timePtr = seconds;
- return SUCCESS;
- }
- @
-
-
- 1.4.1.1
- log
- @Initial branch for Sprite server.
- @
- text
- @d17 1
- a17 1
- static char rcsid[] = "$Header: /sprite/src/lib/c/time/RCS/Time_ToParts.c,v 1.4 90/09/11 14:28:37 kupfer Exp $ SPRITE (Berkeley)";
- @
-
-
- 1.3
- log
- @Added Time_FromParts
- @
- text
- @d17 1
- a17 1
- static char rcsid[] = "$Header: Time_ToParts.c,v 1.2 88/06/27 17:23:41 ouster Exp $ SPRITE (Berkeley)";
- d22 5
- @
-
-
- 1.2
- log
- @Use spriteTime.h instead of time.h.
- @
- text
- @d17 1
- a17 1
- static char rcsid[] = "$Header: Time_ToParts.c,v 1.1 88/06/19 14:33:16 ouster Exp $ SPRITE (Berkeley)";
- d42 2
- a43 2
- if((year%4) == 0) {
- return(366);
- d45 6
- d168 79
- @
-
-
- 1.1
- log
- @Initial revision
- @
- text
- @d17 1
- a17 1
- static char rcsid[] = "$Header: proto.c,v 1.2 88/03/11 08:39:08 ouster Exp $ SPRITE (Berkeley)";
- d21 1
- a21 1
- #include "time.h"
- @
-